//Copyright (C) 2013 Julio Espindola
//
//This file is part of VSize Checkers.
//
//VSize Checkers is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//VSize Checkers is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with VSize Checkers.  If not, see <http://www.gnu.org/licenses/>.

package checkers;

class Jump extends Move
{
    public final int cap;
    public final byte capPiece;
            
    Jump(int start, int dest, int cap, byte capPiece)
    {
        super(start, dest);
        this.cap = cap;
        this.capPiece = capPiece;
    }
    
    Jump(int newDest, Jump j)
    {
        super(j.start, newDest);
        cap = j.cap;
        capPiece = j.capPiece;
    }
    
//    void make(Board b)
//    {
//        super.make(b);
//        b.setPiece(cap, Piece.EMPTY);
//    }
    
    void make(Board b)
    {
        if(start == dest) return;
        b.setPiece(dest, crowning?(byte)(b.getPiece(start)|Piece.QUEEN):b.getPiece(start));
        b.setPiece(start, Piece.EMPTY);
    }
    
    void undo(Board b)
    {
        if(start == dest) return;
        b.setPiece(start, crowning?(byte)(b.getPiece(dest)^Piece.QUEEN):b.getPiece(dest));
        b.setPiece(dest, Piece.EMPTY);
    }
    
    int getSize()
    {
        return 1;
    }
    
    public String detailedInfo()
    {
        return start + "x" + dest + " " + cap + " "
                + ((capPiece&Piece.BLACK)==0?"W":"B")
                + ((capPiece&Piece.QUEEN)==0?"P":"Q");
    }
    
    public String toString()
    {
        return start + "x" + dest;
    }
    
    public boolean equals(Object obj)
    {
        Jump other = (Jump) obj;
        
        return super.equals(obj)
                && cap == other.cap
                && capPiece == other.capPiece;
    }
}
